#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
#include<assert.h>
using namespace std;

namespace wjx {
	class string
	{
	public :
		static const size_t npos = -1;
		typedef char* iterator;
		typedef const char* const_iterator;

		iterator begin()
		{
			return _str;
		}

		iterator end()
		{
			return _str + _size;
		}
		const_iterator begin()const
		{
			return _str;
		}

		const_iterator end()const
		{
			return _str + _size;
		}

		string(const char* str = "")
		{
			size_t len = strlen(str);
			_str = new char[len+1];
			_size = len;
			_capycity = len;
			strcpy(_str, str);
		}
		string(const string & s1)
		{
			_str = new char[s1._size+1];
			strcpy(_str, s1._str);
			_size = s1._size;
			_capycity = s1._capycity;
		}
		~string()
		{
			delete[] _str;
			_str = nullptr;
			_size = 0;
			_capycity = 0;
		}
		size_t size()const
		{
			return _size; 
		}
		size_t capycity()const
		{
			return _capycity;
		}
		const char* c_str() const
		{
			return _str;
		}
		char& operator[](size_t pos)
		{
			assert(pos < _size);
			return _str[pos];
		}
		const char& operator[](size_t pos) const
		{
			assert(pos < _size);

			return _str[pos];
		}
		void reserve(size_t n);
		void push_back(char ch);
		void append(const char* str);
		string& operator+=(char ch);
		string& operator+=(const char* str);

		void insert(size_t pos, char ch);
		void insert(size_t pos, const char* str);
		void erase(size_t pos, size_t len = npos);

		size_t find(char ch, size_t pos = 0);
		size_t find(const char* str, size_t pos = 0);
		string substr(size_t pos = 0, size_t len = npos);
	private:
		char* _str;
		size_t _size;
		size_t _capycity;

		static const size_t npos;
	};
	void test_string();
	ostream& operator<<(ostream& out, string& s1);
	istream& operator<<(istream& in, string s1);
}